using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace StructureMap.WcfIntegration
{
    public class StructureMapServiceHost : ServiceHost
    {
        private readonly IContainer container;

        public StructureMapServiceHost(Type serviceType,IContainer container, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
      {
          this.container = container;
      }

        protected override void OnOpening()
        {
            Description.Behaviors.Add(new StructureMapServiceBehavior(container));

            foreach(var registeredBehavoir in container.GetAllInstances<IServiceBehavior>())
            {
                Description.Behaviors.Add(registeredBehavoir);
            }

            base.OnOpening();
        }
    }
}